package com.stageadminserver.adminserver.controller;

import com.stageadminserver.adminserver.service.WorksInfoService;
import com.stagecommon.common.pojo.RespBean;
import com.stagecommon.common.pojo.WorksInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: yxl
 * @since: 2021-11-27
 **/
@Slf4j
@RestController
@RequestMapping("/worksInfo")
public class WorksInfoController {

    @Autowired
    private WorksInfoService worksInfoService;

    /**
     * ��ҳ��ȡ��Ʒ
     * @param currentPage
     * @param size
     * @param worksInfo
     * @return
     */
    @PostMapping("/searchWorksInfo")
    public RespBean searchWorksInfo(@RequestParam(defaultValue = "1") Long currentPage,
                                    @RequestParam(defaultValue = "10") Long size,
                                    @RequestBody WorksInfo worksInfo){
        return worksInfoService.getWorksInfoByPage(currentPage, size, worksInfo);
    }

    /**
     * ������Ʒid�޸���Ʒ��Ϣ
     * @param worksInfo
     * @return
     */
    @PostMapping("/changeWorkById")
    public RespBean<Integer> changeWorkById(@RequestBody WorksInfo worksInfo){
        return worksInfoService.updateWorkById(worksInfo);
    }

    /**
     * ͨ����Ʒidɾ����Ʒ
     * @param worksInfo
     * @return
     */
    @PostMapping("/deleteWorkById")
    public RespBean<Integer> deleteWorkById(@RequestBody WorksInfo worksInfo){
        return worksInfoService.deleteWorkById(worksInfo);
    }

    /**
     * �ϴ���Ʒ�ļ�
     * @param file
     * @param posterFile
     * @param worksInfo
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadFile")
    public RespBean uploadFile(MultipartFile file, MultipartFile posterFile, WorksInfo worksInfo) throws Exception {
        return worksInfoService.uploadFile(file, posterFile, worksInfo);
    }

    /**
     * ��ѯ������Ʒ
     * @return
     */
    @PostMapping("/selectAllWorks")
    public RespBean<List<WorksInfo>> selectAllWorks(){
        return worksInfoService.selectAllWorks();
    }

    /**
     * ������Ʒid��ȡ��Ʒ��Ϣ
     * @param worksInfo
     * @return
     */
    @PostMapping("/getWorkInfoById")
    public RespBean<WorksInfo> getWorkInfoById(@RequestBody WorksInfo worksInfo){
        return worksInfoService.selectWorkInfoById(worksInfo.getWorkId());
    }


}
